package com.example.cardgame.model

import java.io.Serializable

class Card(private var suit: String?, private var rank: String?, var isChosen: Boolean=false, var isMatched:Boolean=false) : Serializable{
    companion object {
        val validSuits = arrayOf("♥", "♦", "♠", "♣")
        val rankStrings = arrayOf("A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K")
    }

    override fun toString(): String {
        return suit+rank
    }

    fun match(otherCards: Array<Card>, matchCount: Int): Int {
        var score = 0
        if (matchCount == 2 && otherCards.size == 1) {
            val firstCard = otherCards[0]
            if (this.suit == firstCard.suit) {
                score = 1
            } else if (this.rank == firstCard.rank) {
                score = 4
            }
        } else if (matchCount == 3 && otherCards.size == 2) {
            val firstCard = otherCards[0]
            val secondCard = otherCards[1]
            if (this.suit == firstCard.suit && this.suit == secondCard.suit) {
                score = 4
            } else if (this.rank == firstCard.rank && this.rank == secondCard.rank) {
                score = 8
            }
        }
        return score
    }
}